<template>
  <el-dialog
    width="250px"
    title="继续重跑"
    :visible="dialogVisible"
    @close="close"
  >
    <el-form
      :model="form"
    >
      <el-form-item
        prop="flag"
      >
        <el-select
          v-model="form.flag"
          placeholder="请选择"
        >
          <el-option
            v-for="item in flagOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
    </el-form>

    <span
      slot="footer"
    >
      <el-button
        @click="close"
      >
        取消
      </el-button>
      <el-button
        type="primary"
        @click="submit"
      >
        确定
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
import coldApi from '@/api/coldStandby/index'
const form = {
  flag: '',
  order: 'QL',
  mark: '',
  dbName: '',
  tableName: ''
}
export default {
  props: {
    dialogVisible: Boolean,
    selection: Object,
    type: String

  },
  data() {
    return {
      form: {...form},
      flagOptions: []
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        if (this.selection.flag === 'WG') {
          this.flagOptions = [
            { label: 'WG', value: 'WG' },
            { label: 'LB', value: 'LB' }
          ]
        } else {
          this.flagOptions = [
            { label: 'JQ', value: 'JQ' },
            { label: 'LBNAS', value: 'LBNAS' }
          ]
        }
        this.form.flag = this.selection.flag
        this.form.mark = this.selection.mark
        this.form.dbName = this.selection.dbName
        this.form.tableName = this.selection.tableName
      } else {
        this.resetForm()
      }
    }
  },
  methods: {
    async submit() {
      if (this.selection.taskName.includes('【LT】')) {
        this.type === '统计' ? coldApi.ltContinue(this.form) 
          : coldApi.continueFullAudit(
            {
              ...this.form,
              order: ''
            })
      } else {
        this.type === '统计' ? coldApi.continueCbCompAuditTask(this.form) : coldApi.continueFullAudit(this.form)
      }
      setTimeout(() => {
        this.$message.success('继续重跑开始')
        this.close()
      }, 500)
    },
    close() {
      this.$emit('close')
    },
    resetForm() {
      this.form = {...form}
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
